<?php


namespace app\controller;


use app\model\Result;
use app\service\UserService;

use app\utils\Datetime;
use think\facade\Request;

/**
 * 用户
 */
class UserController
{
    /**
     * 用户手机号密码登录
     */
    public function passwordLogon() {

        $param['phone'] = Request::param('phone');
        $param['password'] = Request::param('password');

        $res = UserService::passwordLogon($param);

        if($res == '[]'){
            return json(Result::index(100,'未找到该用户',''));
        }
        if($res['password']==$param['password']) {
            return json(Result::index(200,'登录成功',$res));
        } else{
            return json(Result::index(100,'用户名或密码错误',''));
        }
    }

    /**
     * 用户注册
     */
    public function register() {

        $param['username'] = Request::param('username');
        $param['phone'] = Request::param('phone');
        $param['password'] = Request::param('password');
        $param['create_time'] = Datetime::today();
        $param['status'] = 1;
        $param['love_num'] = 0;
        $param['money'] = 0;
        $param['coin_num'] = 0;
        $param['coupon_num'] = 0;
        $param['buy_num'] = 0;
        $param['clock_day_num'] = 0;
        $param['comment_num'] = 0;
        $param['allowance'] = 0;

        return json(UserService::register($param));
    }

    /**
     * 更新用户信息
     */
    public function userUpdate() {

        $param['uuid'] = Request::param('uuid');
        $param['name'] = Request::param('name');
        $param['username'] = Request::param('username');
        $param['phone'] = Request::param('phone');
        $param['sex'] = Request::param('sex');
        $param['password'] = Request::param('password');
        $param['head_img'] = Request::param('head_img');
        $param['autograph'] = Request::param('autograph');
        $param['synopsis'] = Request::param('synopsis');
        $param['address'] = Request::param('address');

        return json(UserService::userUpdate($param));
    }

    /**
     * 获取用户信息
     */
    public function queryUserByUuid() {

        $param['uuid'] = Request::param('uuid');

        return json(UserService::queryUserByUuid($param));
    }
}
